" vim:foldmethod=marker commentstring="%s

" General options 
" Miscellaneous 

runtime! debian.vim

" fuck vi! long live vim!
set nocompatible

" mode filetype
filetype on
filetype plugin on

" indentation FTW.. also plugins FTW! heh
filetype indent plugin on

" line numbers
se nu
set nocp

" set code completion for each filetype
autocmd FileType python source ~/.vim/python.vim
autocmd FileType python set omnifunc=pythoncomplete#Complete

autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
autocmd FileType c set omnifunc=ccomplete#CompleteCpp

" save sessions 
" http://notvincenz.blogspot.com/2007/03/vim-sessions.html
set sessionoptions=blank,buffers,curdir,folds,help,resize,tabpages,winsize
map <f9> :mksession! ~/.vim/.session <cr>
map <f10> :source ~/.vim/.session <cr>


" automatically flush to disk when using :make, etc.
set autowrite
"
" Display 
" color!
syntax on

" color line numbers subtly
highlight LineNr      term=bold cterm=NONE ctermfg=DarkGrey ctermbg=NONE gui=NONE guifg=DarkGrey guibg=NONE 

" lines, cols in status line
set ruler

" current mode in status line
set showmode

" display the number of (characters|lines) in visual mode, also cur command
set showcmd

" a - terse messages (like [+] instead of [Modified]
" t - truncate file names
" I - no intro message when starting vim fileless
set shortmess=atI

" status line on line 2
set laststatus=2

" display as much of the last line as possible if it's really long
" also display unprintable characters as hex
set display=lastline,uhex

" give three lines of context when moving the cursor around
set scrolloff=3

" don't redraw the screen during macros etc (NetHack's runmode:teleport)
set lazyredraw

" highlight all matches, we'll see if this works with a different hilight
set hlsearch

" highlight matching parens for .2s
set showmatch
set matchtime=2

" threshold for reporting number of lines changed
set report=0

" highlight advanced perl vars inside strings
let perl_extended_vars=1

" POD!
let perl_include_pod=1
"
" Improve power of commands 
" incremental search!
set incsearch

" make tilde (flip case) an operator
set tildeop

" backspace over autoindent, end of line (to join lines), and preexisting test
set backspace=indent,eol,start

" add the dictionary to tab completion
set dictionary=/usr/share/dict/words
set complete+=k

" tab completion in ex mode
set wildmenu

" when doing tab completion, ignore files with any of the following extensions
"set wildignore+=.log,.out,.o

" remember lotsa fun stuff
set viminfo='1000,f1,/50,:50,<50,n~/.viminfo

" add : as a file-name character (mostly for Perl's mod::ules)
set isfname+=:
"
" Make vim less whiny 
" :bn with a change in the current buffer? no prob!
set hidden

" no bells whatsoever
set vb t_vb=

" if you :q with changes it asks you if you want to continue or not
set confirm

" 100 milliseconds for escape timeout instead of 1000
set ttimeoutlen=100
"
" Indentation 
" no-longer skinny tabs!
set tabstop=4

" set to the same as tabstop (see #4 in :help tabstop)
set shiftwidth=4

" if it looks like a tab, we can delete it like a tab
set softtabstop=4

" no tabs! spaces only..
set expandtab

" do not break lines when line lenght increases
set textwidth=0

" < and > will hit indentation levels instead of always -4/+4
set shiftround

" new line has indentation equal to previous line
set autoindent

" braces affect autoindentation
set smartindent

" The following are commented out as they cause vim to behave a lot
" differently from regular Vi. They are highly recommended though.
set showcmd		" Show (partial) command in status line.
set showmatch		" Show matching brackets.
"set ignorecase		" Do case insensitive matching
set smartcase		" Do smart case matching
"set incsearch		" Incremental search
"set autowrite		" Automatically save before commands like :next and :make
"set hidden             " Hide buffers when they are abandoned
set mouse=a		" Enable mouse usage (all modes) in terminals

" figure out indent when ; is pressed
set cinkeys+=;

" align break with case in a switch
set cinoptions+=b1
"
" Folding 
" fold only when I ask for it damnit! (three curly braces)
set foldmethod=marker

" close a fold when I leave it
set foldclose=all
"
" Tags 
set tags+='./.tags,.tags' " add .tags files
set tags+='./../tags,../tags,./../.tags,../.tags' " look in the level above
"
"

" Colors 
" miscellaneous 
set bg=light
" 
" word completion menu 
highlight Pmenu      ctermfg=grey  ctermbg=darkblue
highlight PmenuSel   ctermfg=red   ctermbg=darkblue
highlight PmenuSbar  ctermbg=cyan
highlight PmenuThumb ctermfg=red

highlight WildMenu ctermfg=grey ctermbg=darkblue
"
" folding 
highlight Folded     ctermbg=black ctermfg=darkgreen
"
" hlsearch 
highlight Search NONE ctermfg=lightred
"
"

" Autocommands 
" When editing a file, always jump to the last cursor position 
autocmd BufReadPost *
\  if line("'\"") > 0 && line("'\"") <= line("$") |
\    exe "normal g`\"" |
\  endif
"
" Skeletons 
autocmd BufNewFile *.py silent 0read ~/.vim/skeleton/skeleton.py   | normal G
"autocmd BufNewFile *.pl silent 0read ~/.vim/skeleton/perl.pl     | normal G
"autocmd BufNewFile *.t  silent 0read ~/.vim/skeleton/perl-test.t | normal G
"autocmd BufNewFile *.c  silent 0read ~/.vim/skeleton/c.c         | normal 4j$
"autocmd BufNewFile *.hs silent 0read ~/.vim/skeleton/haskell.hs  | normal Gk$
"
" Auto +x 
au BufWritePost *.sh !chmod +x %
au BufWritePost *.pl !chmod +x %
"
" Automatically distribute my vimrc to the servers I use 
"autocmd BufWritePost ~/.vimrc !scp ~/.vimrc katron.org:public_html/vimrc
"autocmd BufWritePost ~/.vimrc !scp ~/.vimrc eidolos@crawl.akrasiac.org:.eidovimrc
"autocmd BufWritePost ~/.vim/skeletons/* !scp % katron.org:.vim/skeletons/
"autocmd BufWritePost ~/.vim/skeletons/* !scp % eidolos@crawl.akrasiac.org:.vim/skeletons/
"
" Perl 
autocmd FileType perl setlocal makeprg=$VIMRUNTIME/tools/efm_perl.pl\ -c\ %\ $*
autocmd FileType perl setlocal errorformat=%f:%l:%m
autocmd FileType perl setlocal keywordprg=perldoc\ -f
"
"

" Insert-mode remappings/abbreviations 
" Hit <C-a> in insert mode after a bad paste (thanks absolon) 
inoremap <silent> <C-a> <ESC>u:set paste<CR>.:set nopaste<CR>gi
"
" Use <C-t> like irssi to transpose characters in insert mode 
imap  <Esc>xPgi
"
" Words I misspell.. 
iabbrev lamdba lambda
"
" Convenience remappings 
imap ,t <C-R>=strftime("%Y %b %d, %H:%M:%S")<CR>
"

" Normal-mode remappings 
" spacebar (in command mode) inserts a single character before the cursor
nmap <Space> i <Esc>r

" have Y behave analogously to D rather than to dd
nmap Y y$

nnoremap \\ \
nmap \/ :nohl<CR>
nmap \s :syntax sync fromstart<CR>

" darcs convenience mappings 
nmap \da  :execute 'w  <bar> !darcs add %'<CR>
nmap \dA  :execute 'wa <bar> !darcs amend-record'<CR>
nmap \dr  :execute 'wa <bar> !darcs record'<CR>
nmap \dR  :execute 'w  <bar> !darcs record %'<CR>
nmap \dn  :execute 'wa <bar> !darcs whatsnew   <bar> less'<CR>
nmap \dN  :execute 'w  <bar> !darcs whatsnew % <bar> less'<CR>
nmap \dd  :execute 'wa <bar> !darcs diff -u    <bar> less'<CR>
nmap \dD  :execute 'w  <bar> !darcs diff -u %  <bar> less'<CR>
nmap \dc  :execute '!darcs changes             <bar> less'<CR>
nmap \dqm :execute '!darcs query manifest      <bar> less'<CR>
nmap \dt  :execute '!darcs tag'<CR>
nmap \dp  :execute '!darcs push'<CR>
nmap \du  :execute '!darcs unrecord'<CR>
nmap \db  :execute "w <bar> :execute '!darcs revert %'   <bar> :execute 'e'"<CR>
nmap \dB  :execute "w <bar> :execute '!darcs unrevert %' <bar> :execute 'e'"<CR>
"

" testing mappings
autocmd FileType perl nnoremap \t :execute 'wa <bar> !prove -l t 1>/dev/null'<CR>
autocmd FileType perl nnoremap \T :execute 'wa <bar> !prove -lv t'<CR>

nmap <Right> <C-W>l
nmap <Left>  <C-W>h

autocmd FileType help nnoremap <CR> <C-]>
autocmd FileType help nnoremap <BS> <C-T>

" damnit cbus, you've won me over
vnoremap < <gv
vnoremap > >gv
" Make the tab key useful 
function TabWrapper()
  if strpart(getline('.'), 0, col('.')-1) =~ '^\s*$'
    return "\<Tab>"
  elseif exists('&omnifunc') && &omnifunc != ''
    return "\<C-X>\<C-N>"
  else
    return "\<C-N>"
  endif
endfunction
imap <Tab> <C-R>=TabWrapper()<CR>
"
" Painless spell checking (F11) 
function s:spell()
    if !exists("s:spell_check") || s:spell_check == 0
        echo "Spell check on"
        let s:spell_check = 1
        setlocal spell spelllang=en_us
    else
        echo "Spell check off"
        let s:spell_check = 0
        setlocal spell spelllang=
    endif
endfunction
map <F11> :call <SID>spell()<CR>
imap <F11> <C-o>:<BS>call <SID>spell()<CR>
"
"


" Yankring 
let g:yankring_separator = ' '
let g:yankring_n_keys = 'yy dd yw dw ye de yE dE yiw diw yaw daw y$ d$ Y D yG dG ygg dgg' " yf yt df dt yF yT dF dT y, d,'

function! YRRunAfterMaps()
    nnoremap Y :<C-U>YRYankCount 'y$'<CR>
endfunction
"


" share clipboard with windows clipboard
set clipboard+=unnamed

let g:miniBufExplMapWindowNavArrows = 1
let g:miniBufExplMapCTabSwitchWindows = 1

" Execute python scripts
map <f5> :w\|!python %<cr>
map <f6> :w\|!python % -t<cr>

imap <f3> <C-x><C-o><C-p>

:set statusline=%F%m%r%h%w\ (%{&ff})\ Type=%Y\ ASCII=\%03.3b\ HEX=\%02.2B\ Pos=%04l,%04v\ Lines=%L\ [%p%%]\ 

" Taglist stuff
nnoremap <silent> <F8> :TlistToggle<CR>
let Tlist_Exit_OnlyWindow = 1
